package com.subfg.api.rabbitmq.consumer;


import com.rabbitmq.client.Channel;
import com.subfg.api.rabbitmq.constant.QueueApi;
import com.subfg.common.rabbitmq.constant.QueueContentModel;
import com.subfg.common.util.common.TimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.amqp.core.Message;

import java.io.IOException;

@Component
public class MessageReceiver {
    private Logger log = LoggerFactory.getLogger(MessageReceiver.class);



    @RabbitListener(queues = QueueApi.QUEUE_MESSAGE)
    public void messageHandler(Message message, QueueContentModel queueModel, Channel channel) throws IOException {
        log.info("正在进行消息记录!!! 队列id==>>>{}, 消息主题==>>>{}, 已消费==>>>{}次", queueModel.getId(), queueModel.getSubject(), queueModel.getCount());
        Long currentTime = TimeUtil.getCurrentTime();

        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
